<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台信息</title>
<link rel="stylesheet" type="text/css" href="<{$css}>bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="<{$css}>style.css"/>
<script language="javascript" src="<{$script}>jquery-1.7.js"></script>
<script language="javascript" src="<{$script}>bootstrap.min.js"></script>
</head>
<body>
<div class="TopBar">
  <div class="logo"><img src="<{$images}>logo.png" /></div>
  <h1>后台管理</h1>
  <div class="text-right">欢迎 <b><{$Think.session.username}></b> 后台管理中心 <a href="__APP__/Login/doLogout">退出</a></div>
</div>
<div class="LeftMenu">
  <div class="hd">导航菜单</div>
  <div class="bd">
    <a href="index.html" >留言</a>
    <a href="dingyu.html" class="on">订阅</a>
  </div>
  
</div>
<div class="contentBox">
  <div class="content">
   <table class="table table-striped table-hover" >
    <tr>
    <th width="8%" align="center">选择</th>
    <th width="10%" align="center">序号</th>
    <th width="22%" align="center">邮箱</th>
    <th width="15%" align="center">订阅时间</th>
    <th width="40%" align="center"></th>
    <!-- <th width="10%" align="center">操作</th> -->
  </tr>
  <tbody id="dylist">
  <foreach name='list' item='vo'>
  <tr id="id_<{$vo.id}>">
    <td align="center"><input type="checkbox" name="email" value="<{$vo.email}>" /></td>
    <td align="center"><{$vo.id}></td>
    <td align="center"><{$vo.email}></td>
    <td align="center"><{$vo.time|date='Y-m-d',###}></td>
    <td align="center"></td>
    <!-- <td align="center"><a href="javascript:;" data-del="<{$vo.id}>" >删除</a></td> -->
  </tr>
  </foreach>
  </tbody>
  <tr>
    <td align="center"><label><input type="checkbox" /> 全选</label></td>
    <td colspan="6" align="left">
      <button type="button" class="btn btn-primary"  id="sendBtn">发送邮件</button>     
    </td>
  </tr>
</table>
<div class="text-center"><{$page}></div>
<input type="hidden" id="IdDel" /> 
  </div>
<script type="text/javascript">
$(function(){
  $('[data-del]').click(function(event) {
    var id = $(this).attr('data-del');
    $('#IdDel').val(id);
    $("#popup").fadeIn(200, function() {
      $("#popup").find('.tips').html('确定要删除此条留言');
    });
  });
 $('#popupClose').click(function(event) {
   $("#popup").hide();
    $("#popup").find('.tips').html('');  
 });
 $('#popupOk').click(function(event) {
  $("#popup").hide()
  $("#popup").find('.tips').html('');
   var iddel = $('#IdDel').val();
   loading();
  $.ajax({
      url: '__URL__/del',
      type: 'POST',
      dataType: 'json',
      data: { "id": iddel},
      success: function (data) {
          if (data.status ==1) {
              setTimeout(function(){
                $.tips.success(data.info);
                $('#id_'+iddel).fadeOut('1000', function() {
                  $(this).remove();
                });
                $("#loading").remove();
              }, 300)
              
          } else {
              $.tips.error(data.info);
              $("#loading").remove();
          }
          
      }
  });
 });
 function loading(type){
                  var $body = $('body');
                  var html = '<div id="loading" class="'+type+'"><div class="opa"></div><div class="bd">加载中…</div></div>' 
                  $(html).appendTo($body);
                }

(function($){ 
                  $.tips = {
                  init:function(center,type) {
                    var $window = $(window);
                    var $body = $('body');
                    var html = '<div class="tipsdailog '+ type +'" >'+center+'</div>';
                    $(html).appendTo($body);
                    var box = $('.tipsdailog');
                    var top = $window.height()/2-box.outerHeight()/2-40;
                    var left = $window.width()/2-box.outerWidth()/2;
                    box.css({
                      opacity:0,
                      left:left+'px',
                      top:top+'px'
                    });
                    box.fadeTo(300,1);
                    $.tips.hide(3000);
                  },
                  success:function(center) {
                    $.tips.init(center,'tips-success');         
                  },
                  error:function(center) {
                    $.tips.init(center,'tips-error');         
                  },
                  hide:function(t) {
                    var box = $('.tipsdailog');
                    setTimeout(function(){
                      box.remove();
                    },t);
                  }
                  }
                  })(jQuery);

        $('#sendBtn').click(function(event) {
          if ($('#dylist input[name=email]:checked').length==0) {
            $.tips.error('请选择要发送的邮件');
            return
          } else{
            $('#myModal').modal('show');
          };
        });
        $('#sendEmail').click(function(event) {
          var arr = [];
          $('#dylist input[name=email]:checked').each(function(index, el) {
            arr.push($(this).val());
          });
           var title = $('#emailTitle');
           var text = $('#emailText');
           if (title.val()=='') {
              $.tips.error('发送标题不能为空');
              title.focus();
              return
           }
           if (text.val()=='') {
              $.tips.error('发送内容不能为空');
              text.focus();
              return
           }
           loading('opa0');
           $.ajax({
      url: '__URL__/sendEmail',
      type: 'POST',
      dataType: 'json',
      data: { "email": arr,"title": title.val(),"content": text.val()},
      success: function (data) {
          if (data.status ==1) {
              setTimeout(function(){
                $.tips.success(data.info);
                //$('#myModal').modal('hide');
                title.val('');
                text.val('');
                $("#loading").remove();
              }, 300)
              
          } else {
              $.tips.error(data.info);
              $("#loading").remove();
          }
          
      }
  });
        });
        })
</script>

</div>
<div class="popup" id="popup">
    <div class="opa"></div>
    <div class="popupBox">
      <div class="popupbody" >
        <div class="tips"></div>
      </div>
      <div class="popupfooter">
        <a id="popupClose" class="fore1" href="javascript:;">取消</a>
        <a id="popupOk" href="javascript:;">确定</a>
      </div>
    </div>
  </div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="h4 modal-title" id="ModalLabel">邮件内容</h4>
      </div>
      <div class="modal-body">
          <div class="form-group">
            <label for="recipient-name" class="control-label">邮件标题:</label>
            <input type="text" class="form-control" id="emailTitle">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">邮件内容:</label>
            <textarea class="form-control" id="emailText"></textarea>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="sendEmail">发送</button>
      </div>
    </div>
  </div>
</div>
</body>
</html>